package com.qf.myreaim;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;

/**
 * 2019/11/25
 * 键盘敲烂，月薪过万
 * 登高必自卑，行远必自迩。
 * 不忘初心：像初学者一样拥有一颗谦虚、开放的心态。
 * 李学峰
 */
public class ReamlA extends AuthorizingRealm {
    //处理授权
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }
        //处理认证
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        //1.先得到提交的token中的用户名和密码
        String username =(String)authenticationToken.getPrincipal();
        char[] password = (char[])authenticationToken.getCredentials();
        //2.判断
        String s = new String(password);
        if (username.equals("admin")&&s.equals("123")){
            return new SimpleAuthenticationInfo(username,password,"mylxf");
        }

        return null;
    }
}
